import { defineConfig } from 'vite'
import { resolve } from 'path'
import vue from '@vitejs/plugin-vue'
import styleImport from 'vite-plugin-style-import'

// https://vitejs.dev/config/
export default defineConfig({
  base: './', // 开发或生产环境服务的公共基础路径。
  build: {
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString()
          }
          return id
        }
      }
    }
  },
  server: {
    open: true,
    cors: true,
    proxy: {
      '/uploadImage': {
        target: 'http://test1.xunmengvip.com:7720',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/uploadImage/, '')
      }
    }
  },
  resolve: {
    alias: {
      '@': resolve('./src'),
      vue: 'vue/dist/vue.esm-bundler.js' // 定义vue的别名，如果使用其他的插件，可能会用到别名
    }
  },
  plugins: [
    vue({
      template: {
        compilerOptions: {
          isCustomElement: (tag) => tag.startsWith('amplify-')
        }
      }
    }),
    styleImport({
      libs: [
        {
          libraryName: 'ant-design-vue',
          esModule: true,
          resolveStyle: (name) => `ant-design-vue/es/${name}/style/css`
        }
      ]
    })
  ]
})
